package com.zl.autocode.common.utils.generator.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class CfgTable implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private String tableCode="";
    private String tableName="";
    private String tableTitle="";
    private String tableDesc="";
    private String tableJavaCode="";
    private String tableJavaFullCode="";
    private String tableJavaCode2="";
    private String tableAlias="";
    private String selectTemplate="";
    private String needFlag="";
    private String tableType="";
    private String tableKeyType="";
    private String tableKeyImpl="";
    
    /** 自定义标志.  */
    private String customField="";
    private String customField2="";
    private String customField3="";
    private String customField4="";
    
    private List<CfgTableRel> tableRels=new ArrayList<>();
    
    private List<CfgTableInterface> sqlInterfaces=new ArrayList<>();
    private Map<String, CfgTableInterface> sqlInterfacesMap=new HashMap<>();
    
    private Map<String,String> tags=new HashMap<>();
    //特殊处理下
    private String name_dao="";
    private String lname_dao="";
    private String name_entity="";
    private String lname_entity="";
    private String name_entityVo="";
    private String lname_entityVo="";
    private String name_resBase="";
    private String lname_resBase="";
    private String name_resBase2="";
    private String lname_resBase2="";
    
    private List<CfgTableEntity> ownEntity=new ArrayList<>();//自身字段
    private List<CfgTableEntity> primaryEntity=new ArrayList<>();//主键字段
    private List<CfgTableEntity> generalEntity=new ArrayList<>();//一般字段
    private List<CfgTableEntity> otherEntity=new ArrayList<>();//追加字段
    
    private String tableData="";//表主体
    private List<CfgTableEntity> whereData=new ArrayList<>();//条件主体
    private List<List<CfgTableEntity>> chooseWhereData=new ArrayList<>();
    private List<CfgTableEntity> mustWhereData=new ArrayList<>();
    private List<CfgTableEntity> emptyWhereData=new ArrayList<>();
    
    
    public CfgTableEntity getColByJavaCode(String columnJavaCode){
        List<CfgTableEntity> data = this.getOwnEntity();
        if(data!=null && data.size()>0){
            for(CfgTableEntity x:data){
                if(x.getColumnJavaCode().equals(columnJavaCode)){
                    return x;
                }
            }
        }
        return null;
    }
    
    public CfgTableEntity keyGenerated(){
        if(primaryEntity!=null && !primaryEntity.isEmpty()){
            return primaryEntity.get(0);
        }
        return null;
    }
}
